package BNS.kingPawn;

import java.io.*;
import BNS.graphs.*;
import BNS.plumbing.*;

/** <p>This class implements a version of the King&Pawn game.
Tipping is not allowed.</p>

<p>When the game reaches a state of maximum social welfate, the game state 
corresponds to a maximum independent set (IS) in the graph. </p>

<p>Payoffs to individual players depend on the roles chosen by themselves and others,
and are accumulated continuously during play time.</p>
<p>The counterpart class in the client machine is a KingPawnPersona.</p>
*/
public class KingPawnGame extends MarketISGame {
	
	protected static final long serialVersionUID = 01L;
	
	/** Creates a serializable game with all parameters initialized.
	@param gp a GraphPack defining graph views for all players.
	@param time the maximum amount of game time allowed
	@param leanPay the base pay given to a Pawn node
	@param phatPay the gross pay given to a King node that has no King neighbours 
	*/
	public KingPawnGame(GraphPack gp, int time, float leanPay, float phatPay) {
		super(gp, time, leanPay, phatPay);
		}	
	
	/** returns a String indicating the type of game this is. */
	public String getTitle() { return "KingPawnGame"; }
	
	/** invoked (indirectly) by a Client to change the state of a game.
	@param changeObj an Object of design specialized to the game type.
	@return indicates success at making the change.
	It returns true iff the game is not over, the game is not paused, 
	and the game had no errors while trying to carry out the changes implied by changeObject. 
	The classtype of the changeObject determines where this request gets routed next. */
	public boolean alter(ClientLiaison client, Serializable changeObj) {
		long tstamp= clock.getElapsedTime();
		if (changeObj instanceof Integer) return changeColor(tstamp,client,(Integer)changeObj);
		return false;
		}
	
	/** Constructs and returns a BNSPersona for a given client to play a given node.
	This method is required by BNSGameController interface.
	@param client identifies the ClientLiaison object connected to the player's Client.
	@param node the identifying index of the node in the game graph.
	@return the BNSPersona object that runs in the client to implement
			the GUI of this game to the player */
	public BNSPersona getPersona(ClientLiaison client, Node node) {
		System.err.println("creating new KingPawnPersona("+ node +") for "+ client.clientID);
		int nodeIdx= node.getIndex();
		nodeStates[nodeIdx].client= client;
		return new KingPawnPersona(client, grpk.graphlets[nodeIdx],
					gameSize, timeLimit, perfection);
		}
	
	} // EOC KingPawnGame
